package me.lc.hammerheads.sprite.dwarfUnit;

import com.wiyun.engine.actions.Action;
import com.wiyun.engine.actions.Animate;
import com.wiyun.engine.actions.Repeat;
import com.wiyun.engine.actions.RepeatForever;
import com.wiyun.engine.nodes.Animation;
import com.wiyun.engine.nodes.Sprite;
import com.wiyun.engine.types.WYRect;

import me.lc.hammerheads.core.GameSystem;
import me.lc.hammerheads.sprite.Dwarf;
import me.lc.hammerheads.util.AudioHelper;

/**
 * 女矮人1
 * 
 * @author Administrator
 * 
 */
public class DwarfFemale extends Dwarf {

	private static float ItemWidth = GameSystem.tex_female1.getWidth() / 10.0f;
	private static float ItemHeight = GameSystem.tex_female1.getHeight();
	Animation womanAnimation;
	private int leaveLife = getLifeCount();

	@Override
	protected void createDwart() {
		dwarf = Sprite.make(GameSystem.tex_female1,
				WYRect.make(0, 0, ItemWidth, ItemHeight));

		womanAnimation = new Animation(0);
		womanAnimation.addFrame(0.1f, frameAt(2), frameAt(3), frameAt(4),
				frameAt(5), frameAt(6), frameAt(7), frameAt(8), frameAt(9));
	}

	@Override
	public int knock(int power) {
		leaveLife -= power;
		if (leaveLife <= 0) {
			knockOut();
		} else {
			blood.update(leaveLife);
			AudioHelper.womanAU();
			runAction();
		}
		return 1;
	}

	@Override
	protected int getLifeTime() {
		return 7;
	}

	@Override
	protected int getLifeCount() {
		return 2;
	}

	@Override
	protected float getDwarfX() {
		return ItemWidth * 0.11728395f;
	}

	private void runAction() {
		Animate a = (Animate) Animate.make(womanAnimation).autoRelease();
		Action repeat = (Action) RepeatForever.make(a).autoRelease();
		dwarf.runAction(repeat);
	}

	private WYRect frameAt(int x) {
		return WYRect.make(x * ItemWidth, 0, ItemWidth, ItemHeight);
	}

	@Override
	protected void doDwarfAction() {
		// do nothing
	}

	@Override
	protected float getDwarfWidth() {
		return ItemWidth;
	}

	@Override
	protected int getKnockoutScore() {
		return 200;
	}
}
